﻿using System.Diagnostics;

namespace DimensionsHelper.LanguageService.Syntax;

public class MetadataSection : BodiedStatement
{
    private readonly SyntaxToken _declareKeywordToken;
    private StringLiteral? _dataSource;
    private StringLiteral? _labelType;
    private StringLiteral? _language;
    private StringLiteral? _userContext;

    internal MetadataSection(SyntaxToken declareKeywordToken, SyntaxNode? parent) :
        base(SyntaxKinds.MetadataSection, parent)
    {
        SetChildField(ref _declareKeywordToken, declareKeywordToken);
    }


    public SyntaxToken DeclareKeywordToken => _declareKeywordToken;

    public StringLiteral? LanguageName => _language;

    public StringLiteral? UserContext => _userContext;

    public StringLiteral? LabelType => _labelType;

    public StringLiteral? DataSource => _dataSource;


    public MetadataSection Update(StringLiteral? languageName, StringLiteral? userContext, StringLiteral? labelType,
        StringLiteral? dataSource)
    {
        SetChildNullableField(ref _language, StringLiteral.IsDefault, languageName);
        SetChildNullableField(ref _userContext, StringLiteral.IsDefault, userContext);
        SetChildNullableField(ref _labelType, StringLiteral.IsDefault, labelType);
        SetChildNullableField(ref _dataSource, StringLiteral.IsDefault, dataSource);
        return this;
    }


    public override void AcceptVisitor<T>(SyntaxNodeVisitor<T> visitor)
    {
        Accept(visitor, DeclareKeywordToken, LanguageName,
            UserContext, LabelType, DataSource);
        base.AcceptVisitor(visitor);
    }
}


public static partial class NodeFactory
{
    public static MetadataSection CreateMetadataSection(SyntaxNode? parent, SyntaxToken declareKeywordToken,
        StringLiteral? languageName, StringLiteral? userContext, StringLiteral? labelType,
        StringLiteral? dataSource)
    {
        Debug.Assert(declareKeywordToken.IsNode(SyntaxKinds.MetadataKeywordToken));
        MetadataSection section = new(declareKeywordToken, parent);
        return section.Update(languageName, userContext, labelType, dataSource);
    }
}